package org.xiangfei.server.logic;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import io.netty.channel.Channel;

/**
 * @author feesx@qq.com
 * @version 2017年7月9日 下午5:41:30 类说明
 */
public class UserChannelService {
    // 用户对应的渠道 userId->channel
    // TODO 后面改造成redis
    private static Map<String, Channel> userChannelMap = new ConcurrentHashMap<String, Channel>();

    public static void setChannel(String userId, Channel channel) {
        userChannelMap.put(userId, channel);
    }

    public static Channel getChannel(String userId) {
        return userChannelMap.get(userId);
    }

    public static void removeChannel(Channel channel) {
        for (Map.Entry<String, Channel> entry : userChannelMap.entrySet()) {
            if (entry.getValue() == channel) {
                userChannelMap.remove(entry.getKey());
            }
        }
    }

}
